public class test1 {
    //力扣   5.最长回文子串
    public static void main(String[] args) {
        System.out.println(longestPalindrome("babbd"));
    }
    public static String longestPalindrome(String s) {
        int retleft = 0,retright = 0;
        int maxlen = 0;
        char[] chars = s.toCharArray();
        for(int i = 1;i<chars.length;i++){
            //奇数
            for(int left = i-1,right = i+1;;left--,right++){
                if(left<0||right>=chars.length || chars[left]!=chars[right]){
                    if( right-1-left-1+1>maxlen ){
                        retleft = left;
                        retright = right;
                        maxlen = right-1-left-1+1;
                    }
                    break;

                }

            }
            //偶数
            for(int left = i-1,right = i;;left--,right++){
                if(left<0||right>=chars.length || chars[left]!=chars[right]){
                    if(right-1+1-left-1>maxlen){
                        retleft = left;
                        retright = right;
                        maxlen = right-1-left-1+1;
                    }
                    break;

                }

            }
        }
        System.out.println(retleft+1);
        System.out.println(retright);

        return s.substring(retleft+1,retright);

    }
}
